﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ASPItalia.ModelVirtualCasting.Common;
using ASPItalia.ModelVirtualCasting.ObjectModel;
using System.Linq.Expressions;
using System.ComponentModel.Composition;
using ASPItalia.ModelVirtualCasting.Parts;
using System.Data.Entity;

namespace ASPItalia.ModelVirtualCasting.EntityFramework
{
	[Export("PersonRepository", typeof(IPersonRepository))]
	[PartCreationPolicy(CreationPolicy.NonShared)]
	[RepositoryMetadata(Name = "PersonRepository", IsFake = false)]
	public class PersonRepository : BaseRepository<Person>, IPersonRepository
	{
		[ImportingConstructor()]
		public PersonRepository(IContextContainer container)
			: base(container)
		{
		}

		public IQueryable<Person> GetAll()
		{
			return CurrentQueryableSet;
		}

		public IQueryable<Person> Where(Expression<Func<Person, bool>> predicate)
		{
			return CurrentQueryableSet.Where(predicate);
		}

		public long Count(Expression<Func<Person, bool>> predicate)
		{
			return CurrentQueryableSet.Count(predicate);
		}

		public IPersonRepository Include<TProperty>(Expression<Func<Person, TProperty>> path)
		{
			IncludeInternal(path);
			return this;
		}

		public IPersonRepository Include(string path)
		{
			IncludeInternal(path);
			return this;
		}

		public IPersonRepository CreateQuery()
		{
			CreateQueryInternal();
			return this;
		}

		public IPersonRepository EnableLazyLoading()
		{
			SetLazyLoading(true);
			return this;
		}

		public IPersonRepository DisableLazyLoading()
		{
			SetLazyLoading(false);
			return this;
		}

		public IPersonRepository DoNotTrack()
		{
			base.DoNotTrackInternal();
			return this;
		}
	}
}